package com.ztjava.core.directive;

import java.io.IOException;
import java.util.Map;

import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.ehcache.CacheKit;
import com.ztjava.core.Constant;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

public class ParamDirective implements TemplateDirectiveModel{
	@Override
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		String code = "";
		try {
			code = params.get("code").toString();
			Record param = CacheKit.get(Constant.CacheParam, code);
			String value = "";
			if(param!=null){
				value = param.getStr("value");
			}
			env.getOut().write(value);
	        env.getOut().flush();
		}catch	(Exception e) {
			System.out.println("找不到参数："+code);
		}
	}
}
